﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.MassLine
{
    public class PartyMassLineFeedback : EntityBase
    {
        #region 属性
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 电话
        /// </summary>
        public string Telephone { get; set; }
        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID { get; set; }
        /// <summary>
        /// 说明
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 是否匿名
        /// </summary>
        public string Anonymous { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int? OrderNo { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string CreateBy { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public string ModifyBy { get; set; }
        #endregion

        #region 查询管理
        public static DataSet GetGridData(int pageIndex, int pageSize, string BranchID, string Type, string TypeOption = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                 new MySqlParameter()
                {
                DbType = DbType.Int32,
                ParameterName = "Begin",
                Value = (pageIndex) * pageSize
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "PageSize",
                    Value = pageSize
                }
            };
            StringBuilder sbsql = new StringBuilder();
            sbsql.Append(@" select SQL_CALC_FOUND_ROWS pf.id,pf.name,pf.telephone,pf.branchid,pfo.pid,
                            (case IFNULL(pfo.TypeOption,'') when '' then pfo.Type else pfo.Type+'-'+pfo.TypeOption  end) as typeEx,pfo.Opinion
                            ,pfo.Example,pb.BranchName,pf.CreateTime from tblpartymasslinefeedback  pf
                            left join tblpartymasslinefeedbackoption pfo on pf.id=pfo.pid
                            left join tblpartyorgbranch pb on pf.BranchID=pb.BranchID
                                where 1=1");
            if (!string.IsNullOrEmpty(BranchID))
            {
                sbsql.AppendFormat(" and pf.BranchID='{0}'", BranchID);
            }
            if (!string.IsNullOrEmpty(Type))
            {
                if (string.IsNullOrEmpty(TypeOption))
                {
                    sbsql.AppendFormat(" and pfo.Type='{0}'", Type);
                }
                else
                {
                    sbsql.AppendFormat(" and pfo.Type='{0}'", Type);
                    sbsql.AppendFormat(" and pfo.TypeOption='{0}'", TypeOption);
                }
            }
            sbsql.Append(" order by pf.CreateTime desc  LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS()");
            DataSet ds = MySqlHelper.ExecuteDataSet(sbsql.ToString(), parameters.ToArray());
            return ds;
        }

        #endregion
    }
}
